/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.colswe.solestac.control;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import org.colswe.solestac.view.Principal;

/**
 * This classs creates the user's menu panel.
 *
 * @author laarguelless
 * @version 1.1
 */
public class UserMenuFactory {
    
    /**
     * WIDTH LOGOUT = 180.
     */
    public static final int WIDTH_LOGOUT = 180;
    /**
     * HEIGHT = 31.
     */
    private static final int HEIGHT = 31;
    /**
     * POSITION_X = 20.
     */
    private static final int POSITION_X = 20;
    /**
     * POSITION_Y = 40.
     */
    private static final int POSITION_Y = 40;
    /**
     * POSITION_Y_CONSULTAR = 91.
     */
    private static final int POSITION_Y_CONSULTAR = 91;
    /**
     * POSITION_Y_LOGOUT = POSITION_Y + 540.
     */
    private static final int POSITION_Y_LOGOUT = 580;
    /**
     * WIDTH = 220.
     */
    private static final int WIDTH = 220;

    /**The frame that conatins the menu.
     */
    private Principal container;
    /**Constant to the Administrator Role.
     */
    private final String admin = "administrador";
    /**Constant to the Secretary Role.
     */
    private final String secretariaCadeRole = "secretaria CADE";
    /**Constant to the Assistant Role.
     */
    private final String assist = "asistente CADE";

    /**Constructor, the object must have a container.
     * @param newContainer The container for the menu
     */
    public UserMenuFactory(final Principal newContainer) {
        this.container = newContainer;
    }

    /**Creates the buttons according to the role given.
     * @param panel The panel that contains the menu.
     * @param role The role of the user logged in.
     */
    public void createMenuPanel(final JPanel panel, final String role) {
        panel.setVisible(false);
        
        if (role.equals(admin)) {
            
            JButton adminUserButton = new JButton("Administrar usuarios");
            adminUserButton.setBounds(POSITION_X, POSITION_Y, WIDTH, HEIGHT);
            adminUserButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(final ActionEvent ae) {
                    container.userAdministration();
                }                
            });
            panel.add(adminUserButton);            
            
        } else if (role.equals(secretariaCadeRole)) {
            JButton createRequestButton = new JButton("Radicar solicitud");
            createRequestButton.setBounds(POSITION_X, POSITION_Y, WIDTH, HEIGHT);
            createRequestButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(final ActionEvent ae) {
                   container.createRequest();
                }
            });
            panel.add(createRequestButton);
            JButton searchRequestButton = new JButton("Consultar Solicitudes");
            searchRequestButton.setBounds(POSITION_X, POSITION_Y_CONSULTAR, WIDTH, HEIGHT);
            searchRequestButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(final ActionEvent ae) {
                    container.searchRequest();
                }
            });
            panel.add(searchRequestButton);
            
        } else if (role.equals(assist)) {
              
            JButton searchRequestButton = new JButton("Consultar Solicitudes");
            searchRequestButton.setBounds(POSITION_X, POSITION_Y, WIDTH, HEIGHT);
            searchRequestButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(final ActionEvent ae) {
                    container.searchRequest();
                }
            });
            panel.add(searchRequestButton);
        }
        
        JButton logoutButton =  new JButton("Cerrar Sesión");
        logoutButton.setBounds(POSITION_X, POSITION_Y_LOGOUT, WIDTH_LOGOUT, HEIGHT);
        logoutButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent ae) {
                container.logout();
            }
        });
        panel.add(logoutButton);
        panel.setVisible(true);
    }
}
